using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace SqlTools.SchemaReader
{
	public abstract class DbTextObject : DbObject
	{
		protected string _text;

		public DbTextObject() : this("", 0) { }

		public DbTextObject(string name, int id)
			: base (name, id)
		{
			_text = "";
		}

		public string Text
		{
			get { return _text; }
			internal set { _text = value; }
		}

		public override XmlElement CreateXmlElement(XmlDocument doc, XmlNode parent)
		{
			XmlElement el = base.CreateXmlElement(doc, parent);

			XmlCDataSection cdata = doc.CreateCDataSection(_text);

			el.AppendChild(cdata);

			return el;
		}

		public override void LoadXml(XmlElement el, Database db)
		{
			base.LoadXml(el, db);
			
			foreach ( XmlNode node in el.ChildNodes )
			{
				if ( node.NodeType == XmlNodeType.CDATA )
				{
					_text = ( (XmlCDataSection)node ).Data;
				}
			}
		}
	}
}
